package com.k2data.k2app.mapper;

import com.k2data.k2app.domain.po.v1.RFile;
import com.k2data.k2app.mybatis.mapper.K2Mapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 文件信息表
 *
 * @author clb
 * @date 2017年11月28日15:55:08
 */
@Mapper
@Repository
public interface RFileMapper extends K2Mapper<RFile> {
    int insertBatch(List<RFile> list);

    @Select(" SELECT cu.id,cu.customer_id as customerId,cu.file_name as fileName,cu.file_url as fileUrl,cu.size as size " +
            " FROM r_file cu where cu.customer_id = #{customerId} and cu.type = #{type}")
    List<RFile> getByCustomerId(@Param("customerId") Long customerId,@Param("type") String type);

    @Select(" SELECT cu.id,cu.customer_id as customerId,cu.device_id as deviceId, cu.file_name as fileName,cu.file_url as fileUrl,cu.size as size " +
            " FROM r_file cu where cu.device_id = #{deviceId} and cu.type = #{type}")
    List<RFile> getByDeviceId(@Param("deviceId") Long customerId,@Param("type") String type);

    @Select(" SELECT cu.id,cu.customer_id as customerId,cu.device_id as deviceId,cu.event_id as eventId, cu.file_name as fileName,cu.file_url as fileUrl,cu.size as size " +
            " FROM r_file cu where cu.event_id = #{eventId} and cu.type = #{type}")
    List<RFile> getByEventId(@Param("eventId") Long eventId,@Param("type") String type);


    @Delete(" delete from r_file where customer_id = #{customerId} and type = #{type}")
    int deleteByCustomerId(@Param("customerId") Long customerId,@Param("type") String type);

    @Delete(" delete from r_file where device_id = #{deviceId} and type = #{type}")
    int deleteByDeviceId(@Param("deviceId") Long deviceId,@Param("type") String type);

    @Delete(" delete from r_file where event_id = #{eventId} and type = #{type}")
    int deleteByEventId(@Param("eventId") Long eventId,@Param("type") String type);
}
